﻿using System;

namespace Simp.CodeModel.CoreFunctions
{
	/// <summary>Encapsulates a function forcing numbers into a floating point notation.</summary>
	public class FloatingFunction : IFunction
	{
		private static readonly string[] PARAMETER_NAMES = new[] { "number" };

		#region IFunction Members
		string IFunction.FunctionName
		{
			get { return "Floating"; }
		}

		string[] IFunction.ParameterNames
		{
			get { return PARAMETER_NAMES; }
		}

		IFunctionParameterBinding[] IFunction.DefaultParameterValues
		{
			get { return FunctionHelper.EmptyBindings; }
		}

		IFunction IFunction.Simplify(SimplificationMode simplificationMode, params IFunction[] parameters)
		{
			IFunction number = parameters[0];
			RealFunction real = number as RealFunction;

			if (real != null)
			{
				return real;
			}
			else
			{
				RationalFunction rational = number as RationalFunction;

				if (rational != null)
				{
					return new RealFunction((double)rational.Numerator / rational.Denominator);
				}
				else
				{
					IntegerFunction integer = number as IntegerFunction;

					if (integer != null)
					{
						return new RealFunction((double)integer.Value);
					}
					else
					{
						return null;
					}
				}
			}
		}

		IFunction IFunction.AcceptVisitor(IFunctionVisitor visitor)
		{
			return null;
		}
		#endregion
	}
}